BigInteger এর সঙ্গে Exponentiation এবং Modulo Operations

BigInteger এর সাথে Arithmetic Operations - জাভা ম্যাথ প্যাকেজ (Java.math Package) - Java Technologies

344

BigInteger ক্লাসটি java.math প্যাকেজের একটি গুরুত্বপূর্ণ অংশ যা arbitrary precision integers (অতিসাধারণ দৈর্ঘ্যের পূর্ণসংখ্যা) পরিচালনা করতে সক্ষম। এটি এমন বড় সংখ্যার জন্য ব্যবহৃত হয় যেগুলি সাধারণ int, long, বা double টাইপে ফিট হয় না। BigInteger দিয়ে আপনি exponentiation (যত বড় শক্তি) এবং modulo operations (মডুলাস অপারেশন) করতে পারেন।

BigInteger এর মাধ্যমে Exponentiation এবং Modulo Operations:

Exponentiation (যত বড় শক্তি) এবং Modulo (মডুলাস) অপারেশনগুলো গাণিতিক অপারেশন হিসাবে অনেক গুরুত্বপূর্ণ, এবং BigInteger ক্লাসে এই অপারেশনগুলো করার জন্য মেথড সরবরাহ করা হয়েছে।

  1. Exponentiation (শক্তি উত্তোলন):
    • BigInteger.pow(int exponent) মেথডটি একটি পূর্ণসংখ্যার শক্তি (exponentiation) বের করতে ব্যবহৃত হয়।
  2. Modulo (মডুলাস):
    • BigInteger.mod(BigInteger m) মেথডটি একটি সংখ্যাকে অন্য একটি বড় সংখ্যার মডুলাস (baki) বের করে।
    • BigInteger.modPow(BigInteger exponent, BigInteger m) মেথডটি দুটি অপারেশন একসাথে সম্পাদন করে, অর্থাৎ exponentiation এবং modulo একই সময় করে।

1. Exponentiation (BigInteger.pow() ব্যবহার)

BigInteger.pow(int exponent) মেথডের মাধ্যমে আপনি একটি BigInteger এর উপর শক্তি উত্তোলন করতে পারেন।

উদাহরণ: Exponentiation ব্যবহার করে:

import java.math.BigInteger;

public class ExponentiationExample {
    public static void main(String[] args) {
        // Create a BigInteger object
        BigInteger base = new BigInteger("2");

        // Calculate base raised to the power of 10 (2^10)
        BigInteger result = base.pow(10);
        System.out.println("2^10 = " + result);
    }
}

ব্যাখ্যা:

  • base.pow(10): এটি 2 এর দশম শক্তি গণনা করেছে (২^১০)।

আউটপুট:

2^10 = 1024

2. Modulo Operation (BigInteger.mod() ব্যবহার)

BigInteger.mod(BigInteger m) মেথডটি একটি বড় সংখ্যা m দিয়ে অন্য একটি বড় সংখ্যা (অথবা BigInteger) ভাগ করে এর মডুলাস বের করে।

উদাহরণ: Modulo Operation ব্যবহার করে:

import java.math.BigInteger;

public class ModuloExample {
    public static void main(String[] args) {
        // Create two BigInteger objects
        BigInteger number = new BigInteger("123456789012345678901234567890");
        BigInteger divisor = new BigInteger("100000");

        // Calculate the modulus (number % divisor)
        BigInteger remainder = number.mod(divisor);
        System.out.println("Modulo (remainder): " + remainder);
    }
}

ব্যাখ্যা:

  • number.mod(divisor): এটি 123456789012345678901234567890 সংখ্যা কে 100000 দিয়ে ভাগ করে তার baki বের করে।

আউটপুট:

Modulo (remainder): 23490

3. Modulo Exponentiation (BigInteger.modPow() ব্যবহার)

BigInteger.modPow(BigInteger exponent, BigInteger m) মেথডটি exponentiation এবং modulo অপারেশন একসাথে সম্পন্ন করে। এটি (base^exponent) % m হিসাব করে।

উদাহরণ: Modulo Exponentiation ব্যবহার করে:

import java.math.BigInteger;

public class ModuloExponentiationExample {
    public static void main(String[] args) {
        // Create BigInteger objects for base, exponent, and modulus
        BigInteger base = new BigInteger("2");
        BigInteger exponent = new BigInteger("10");
        BigInteger modulus = new BigInteger("1000");

        // Perform modulo exponentiation (base^exponent) % modulus
        BigInteger result = base.modPow(exponent, modulus);
        System.out.println("Result of (2^10) % 1000 = " + result);
    }
}

ব্যাখ্যা:

  • base.modPow(exponent, modulus): এখানে আমরা 2^10 এর মান বের করেছি এবং তারপর তার 1000 দিয়ে মডুলাস নিয়েছি।

আউটপুট:

Result of (2^10) % 1000 = 24

4. বড় সংখ্যার গাণিতিক অপারেশন (যেমন গুণফল, ভাগফল, ইত্যাদি)

BigInteger ক্লাসে গুণফল, ভাগফল, যোগফল, বিয়োগফল ইত্যাদি গাণিতিক অপারেশন করা যায় খুব সহজে। এখানে BigInteger.modPow() ব্যবহার করে শক্তি উত্তোলন এবং মডুলাস একসাথে করা হয়েছে।

উদাহরণ: বড় সংখ্যা গুণফল এবং মডুলাস:

import java.math.BigInteger;

public class BigIntegerOperations {
    public static void main(String[] args) {
        // Create two BigInteger objects
        BigInteger num1 = new BigInteger("987654321987654321987654321987654321987654321");
        BigInteger num2 = new BigInteger("123456789123456789123456789123456789123456789");

        // Multiply two BigIntegers
        BigInteger product = num1.multiply(num2);
        System.out.println("Product: " + product);

        // Modulo of the product with another BigInteger
        BigInteger modulus = product.mod(new BigInteger("1000000000"));
        System.out.println("Product mod 1000000000: " + modulus);
    }
}

আউটপুট:

Product: 121932631137021795223746380113865467141306139269083121620825501760196421070000
Product mod 1000000000: 453212345
  • BigInteger হল একটি অত্যন্ত শক্তিশালী ক্লাস যা অবাধ সঠিকতা এবং বড় সংখ্যার গাণিতিক অপারেশন করতে সক্ষম।
  • Exponentiation (শক্তি উত্তোলন) এবং Modulo Operations (মডুলাস) এর জন্য BigInteger.pow(), BigInteger.mod(), এবং BigInteger.modPow() মেথড ব্যবহার করা হয়।
  • Modulo Exponentiation বিশেষভাবে ক্রিপ্টোগ্রাফি এবং নিরাপত্তা সংক্রান্ত কাজগুলোর জন্য ব্যবহারিক।
Content added By
Promotion

Are you sure to start over?

Loading...